package com.ktjy.t382.ch03.controller;

import com.ktjy.t382.ch03.entity.SysUser;
import com.ktjy.t382.ch03.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {

    @Resource
    private UserService userService;

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/dologin")
    public String dologin(SysUser sysUser, HttpSession session) {
        int count = userService.getUserInfo(sysUser);
        if (count > 0) {
            session.setAttribute("loginUser", sysUser);
            return "hello";
        } else {
            return "error";
        }
    }
}
